Skip to content

sds: additional support for symlink-based key rotation.#13721

Merged
htuch merged 16 commits intoenvoyproxy:masterfrom
htuch:sds-symlink
Nov 13, 2020
Merged

sds: additional support for symlink-based key rotation.#13721
htuch merged 16 commits intoenvoyproxy:masterfrom
htuch:sds-symlink

Conversation

@htuch
Copy link
Member

@htuch htuch commented Oct 23, 2020

There are a few limitations in our existing support for symlink-based
key rotation:

  • We don't atomically resolve symlinks, so a single snapshot might have
    inconsistent symlink resolutions for different watched files.
  • Watches are on parent directories, e.g. for /foo/bar/baz on /foo/bar,
    which doesn't support common key rotation schemes were /foo/new/baz
    is rotated via a mv -Tf /foo/new /foo/bar.

The solution is to provide a structured WatchedDirectory for Secrets to
opt into when monitoring DataSources. SDS will used WatchedDirectory
to setup the inotify watch instead of the DataSource path. On update, it will
read key/cert twice, verifying file content hash consistency.

Risk level: Low (opt-in feature)
Testing: Unit and integration tests added.

Fixes #13663
Fixes #10979
Fixes #13370

Signed-off-by: Harvey Tuch htuch@google.com

@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #13721 was opened by htuch.

see: more, trace.

@htuch
Copy link
Member Author

htuch commented Oct 23, 2020

@mattklein123 @lizan @tsaarni can you take a look? This will address #13663, #10979 and #13370, I'd like to obtain consensus on the API before adding implementation and tests.

Copy link
Member

@tsaarni tsaarni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless of working with only a subset of all DataSource use cases, I like this API.

This will work nicely with Kubernetes symlink swap as well, by leaving subdirectory optional 👍

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a high level LGTM with a few comments.

@htuch
Copy link
Member Author

htuch commented Oct 26, 2020

I've updated the API to avoid modifying DataSource, introducing a new concept of an opt-in WatchedDirectory. I've also added a draft implementation and a very basis integration test. I'd like to achieve agreement on API and design, at which point I can clean up the implementation and fill out the rest of the tests. @lizan @mattklein123 @tsaarni PTAL.

@htuch
Copy link
Member Author

htuch commented Oct 27, 2020

This now uses hash-based comparison of files after reading twice and validated consistency. This is similar to what gRPC is doing.

Copy link
Member

@tsaarni tsaarni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me after the unbound loop in SdsApi::onWatchUpdate() is resolved.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks agreed this seems like a better direction. Flushing out a few API questions/comments.

/wait

@htuch
Copy link
Member Author

htuch commented Oct 27, 2020

PTAL, if this makes sense now in terms of API and hash-based comparison implementation then I can fill in the missing tests/docs and move this out of draft.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an API perspective this LGTM with one question. LMK when ready for review and I can take a look.

/wait

htuch added 6 commits November 9, 2020 18:12
Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
…. Fix format.

Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
@htuch htuch changed the title [WiP] sds/base: additional support for symlink-based key rotation. sds: additional support for symlink-based key rotation. Nov 10, 2020
Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some API comments, thank you!

/wait

Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
@htuch
Copy link
Member Author

htuch commented Nov 13, 2020

@mattklein123 to deal with failure scenarios I had to add some stats, which then forced me to fix SDS stats more generally, since they were broken before (they all ended up anonymously in the root namespace). PTAL and LMK if there's anything else needed around stats here.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks LGTM with small questions.

/wait-any

Comment on lines +263 to +269
// If specified, updates of a file-based *trusted_ca* source will be triggered
// by this watch. This allows explicit control over the path watched, by
// default the parent directory of the filesystem path in *trusted_ca* is
// watched if this field is not specified. This only applies when a
// *CertificateValidationContext* is delivered by SDS with references to
// filesystem paths.
config.core.v3.WatchedDirectory watched_directory = 11;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand how this does anything if there is only a single file above? What's the utility?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say you have a trusted CA files /foo/bar/baz/ca.pem. By default, envoy watches /foo/bar/baz. If you want to reload when baz is atomically moved, you need to set the watch on /foo/bar. This is what this field allows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I think having a concrete example might help for this stuff (or ref link back to the docs where you have the example) as it was pretty hard for me to understand the difference.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Feel free to do any doc updates as a follow up.

@htuch
Copy link
Member Author

htuch commented Nov 13, 2020

Sure, will merge as some folks are depending on this, but I'll take an AI to do the docs followups next week. Thanks.

@htuch htuch merged commit 122257e into envoyproxy:master Nov 13, 2020
htuch added a commit to htuch/envoy that referenced this pull request Nov 15, 2020
Some followup docs tweaks to envoyproxy#13721.

Signed-off-by: Harvey Tuch <htuch@google.com>
htuch added a commit that referenced this pull request Nov 16, 2020
Some followup docs tweaks to #13721.

Signed-off-by: Harvey Tuch <htuch@google.com>
andreyprezotto pushed a commit to andreyprezotto/envoy that referenced this pull request Nov 24, 2020
Some followup docs tweaks to envoyproxy#13721.

Signed-off-by: Harvey Tuch <htuch@google.com>
qqustc pushed a commit to qqustc/envoy that referenced this pull request Nov 24, 2020
…3721)

There are a few limitations in our existing support for symlink-based
key rotation:

We don't atomically resolve symlinks, so a single snapshot might have
inconsistent symlink resolutions for different watched files.
Watches are on parent directories, e.g. for /foo/bar/baz on /foo/bar,
which doesn't support common key rotation schemes were /foo/new/baz
is rotated via a mv -Tf /foo/new /foo/bar.
The solution is to provide a structured WatchedDirectory for Secrets to
opt into when monitoring DataSources. SDS will used WatchedDirectory
to setup the inotify watch instead of the DataSource path. On update, it will
read key/cert twice, verifying file content hash consistency.

Risk level: Low (opt-in feature)
Testing: Unit and integration tests added.

Fixes envoyproxy#13663
Fixes envoyproxy#10979
Fixes envoyproxy#13370

Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Qin Qin <qqin@google.com>
qqustc pushed a commit to qqustc/envoy that referenced this pull request Nov 24, 2020
Some followup docs tweaks to envoyproxy#13721.

Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Qin Qin <qqin@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants